﻿using ClusterAware;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;
namespace ClusterAwareTest
{


    /// <summary>
    ///This is a test class for ClusterManagerTest and is intended
    ///to contain all ClusterManagerTest Unit Tests
    ///</summary>
    [TestClass]
    public class ClusterManagerTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }


        private static ClusterManager _manager;



        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize]
        public static void ClassTestInitialize(TestContext testContext)
        {
        }
        //
        //Use ClassCleanup to run code after all tests in a class have run
        [ClassCleanup]
        public static void ClassTestCleanup()
        {
        }
        //
        //Use TestInitialize to run code before running each test
        [TestInitialize]
        public void Initialize()
        {
            _manager = new ClusterManager
            {
                Username = SharedConsts.User,
                Password = SharedConsts.Pwd,
                Domain = SharedConsts.Domain,
                Machine = SharedConsts.Machine,
                CacheInstances = false
            };
            _manager.Connect();
        }
        //
        //Use TestCleanup to run code after each test has run
        [TestCleanup]
        public void Cleanup()
        {
            _manager.Dispose();
        }
        //
        #endregion

        /// <summary>
        ///A test for EnabledWatcherResourceStateChange
        ///</summary>
        [TestMethod]
        public void EnabledDisabledWatcherResourceStateChangeTest()
        {
            _manager.CacheInstances = true;
            _manager.EnabledWatcherResourceStateChange();
            Thread.Sleep(5000);
            _manager.DisabledWatcherResourceStateChange(10);
            _manager.CacheInstances = false;
            _manager.EnabledWatcherResourceStateChange();
            Thread.Sleep(5000);
            _manager.DisabledWatcherResourceStateChange(10);
        }

        /// <summary>
        ///A test for Refresh
        ///</summary>
        [TestMethod]
        public void RefreshTest()
        {
            _manager.CacheInstances = true;
            _manager.Refresh(RefreshOption.All);
            _manager.Refresh(RefreshOption.Groups);
            _manager.Refresh(RefreshOption.NetworkInterface);
            _manager.Refresh(RefreshOption.Networks);
            _manager.Refresh(RefreshOption.Nodes);
            _manager.Refresh(RefreshOption.Resources);
            _manager.Refresh(RefreshOption.ResourceTypes);
            _manager.CacheInstances = true;
            _manager.Refresh(RefreshOption.All);
            _manager.Refresh(RefreshOption.Groups);
            _manager.Refresh(RefreshOption.NetworkInterface);
            _manager.Refresh(RefreshOption.Networks);
            _manager.Refresh(RefreshOption.Nodes);
            _manager.Refresh(RefreshOption.Resources);
            _manager.Refresh(RefreshOption.ResourceTypes);
        }

        /// <summary>
        ///A test for EnabledWatcherGroupStateChange
        ///</summary>
        [TestMethod]
        public void EnabledDisabledWatcherGroupStateChangeTest()
        {
            _manager.CacheInstances = true;
            _manager.EnabledWatcherGroupStateChange();
            Thread.Sleep(5000);
            _manager.DisabledWatcherGroupStateChange(10);
            _manager.CacheInstances = false;
            _manager.EnabledWatcherGroupStateChange();
            Thread.Sleep(5000);
            _manager.DisabledWatcherGroupStateChange(10);
        }

        /// <summary>
        ///A test for EnabledWatcherClusterObjectRemove
        ///</summary>
        [TestMethod]
        public void EnabledDisabledWatcherClusterObjectRemoveTest()
        {
            _manager.CacheInstances = true;
            _manager.EnabledWatcherClusterObjectRemove();
            Thread.Sleep(5000);
            _manager.DisabledWatcherClusterObjectRemove(10);
            _manager.CacheInstances = false;
            _manager.EnabledWatcherClusterObjectRemove();
            Thread.Sleep(5000);
            _manager.DisabledWatcherClusterObjectRemove(10);
        }

        /// <summary>
        ///A test for EnabledWatcherClusterObjectAdd
        ///</summary>
        [TestMethod]
        public void EnabledDisabledWatcherClusterObjectAddTest()
        {
            _manager.CacheInstances = true;
            _manager.EnabledWatcherClusterObjectAdd();
            Thread.Sleep(5000);
            _manager.DisabledWatcherClusterObjectAdd(10);
            _manager.CacheInstances = false;
            _manager.EnabledWatcherClusterObjectAdd();
            Thread.Sleep(5000);
            _manager.DisabledWatcherClusterObjectAdd(10);
        }

        /// <summary>
        ///A test for EnabledWatcher
        ///</summary>
        [TestMethod]
        public void EnabledDisabledWatcherTest()
        {
            _manager.CacheInstances = true;
            _manager.EnabledWatcher();
            Thread.Sleep(5000);
            _manager.DisabledWatcher();
            _manager.CacheInstances = false;
            _manager.EnabledWatcher();
            Thread.Sleep(5000);
            _manager.DisabledWatcher();
        }

        /// <summary>
        ///A test for Disconnect
        ///</summary>
        [TestMethod]
        public void DisconnectTest()
        {
            _manager.CacheInstances = true;
            _manager.Disconnect();
            _manager.Dispose();
            _manager.CacheInstances = false;
            _manager.Disconnect();
            _manager.Dispose();
        }

        /// <summary>
        ///A test for DisabledWatcherResourceStateChange
        ///</summary>
        [TestMethod]
        public void DisabledWatcherResourceStateChangeTest()
        {
            _manager.CacheInstances = true;
            _manager.DisabledWatcherResourceStateChange(0);
            _manager.Dispose();
            _manager.CacheInstances = false;
            _manager.DisabledWatcherResourceStateChange(0);
            _manager.Dispose();
        }

        /// <summary>
        ///A test for DisabledWatcherGroupStateChange
        ///</summary>
        [TestMethod]
        public void DisabledWatcherGroupStateChangeTest()
        {
            _manager.CacheInstances = true;
            _manager.DisabledWatcherGroupStateChange(0);
            _manager.Dispose();
            _manager.CacheInstances = false;
            _manager.DisabledWatcherGroupStateChange(0);
            _manager.Dispose();
        }

        /// <summary>
        ///A test for DisabledWatcherClusterObjectRemove
        ///</summary>
        [TestMethod]
        public void DisabledWatcherClusterObjectRemoveTest()
        {
            _manager.CacheInstances = true;
            _manager.DisabledWatcherClusterObjectRemove(0);
            _manager.Dispose();
            _manager.CacheInstances = false;
            _manager.DisabledWatcherClusterObjectRemove(0);
            _manager.Dispose();
        }

        /// <summary>
        ///A test for DisabledWatcherClusterObjectAdd
        ///</summary>
        [TestMethod]
        public void DisabledWatcherClusterObjectAddTest()
        {
            _manager.CacheInstances = true;
            _manager.DisabledWatcherClusterObjectAdd(0);
            _manager.Dispose();
            _manager.CacheInstances = false;
            _manager.DisabledWatcherClusterObjectAdd(0);
            _manager.Dispose();
        }

        /// <summary>
        ///A test for DisabledWatcher
        ///</summary>
        [TestMethod]
        public void DisabledWatcherTest()
        {
            _manager.CacheInstances = true;
            _manager.DisabledWatcher();
            _manager.Dispose();
            _manager.CacheInstances = false;
            _manager.DisabledWatcher();
            _manager.Dispose();
        }

        /// <summary>
        ///A test for Connect
        ///</summary>
        [TestMethod]
        public void ConnectTest()
        {
            _manager = new ClusterManager
            {
                Username = SharedConsts.User,
                Password = SharedConsts.Pwd,
                Domain = SharedConsts.Domain,
                Machine = SharedConsts.Machine,
                CacheInstances = true
            };
            _manager.Connect();
            _manager = new ClusterManager
            {
                Username = SharedConsts.User,
                Password = SharedConsts.Pwd,
                Domain = SharedConsts.Domain,
                Machine = SharedConsts.Machine,
                CacheInstances = false
            };
            _manager.Connect();
            _manager.Dispose();
        }
    }
}
